package com.example.demo.controller;

import com.example.demo.Entity.Collect;
import com.example.demo.Service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/collects")
public class CollectController {

    @Autowired
    private CollectService collectService;

    @GetMapping("/user/{userId}")
    public ResponseEntity<List<Collect>> getCollectsByUserId(@PathVariable Long userId) {
        List<Collect> collects = collectService.getCollectsByUserId(userId);
        return ResponseEntity.ok(collects);
    }

    @PostMapping("/{itemId}")
    public ResponseEntity<Void> addCollect(@PathVariable Long itemId, @RequestParam Long userId) {
        collectService.addCollect(itemId, userId);
        return ResponseEntity.ok().build();
    }

    @DeleteMapping("/{itemId}")
    public ResponseEntity<Void> removeCollect(@PathVariable Long itemId, @RequestParam Long userId) {
        collectService.removeCollect(itemId, userId);
        return ResponseEntity.ok().build();
    }
}
